﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sort
{
    /// <summary>
    /// 时间复杂度： O(n*n)
    /// </summary>
    public class BubbleSort
    {
        public int[] arrForSort = new int[100];

        public BubbleSort(int[] arr)
        {
            this.arrForSort = arr;
        }

        public int[] Execute()
        {
            int j, temp;

            int i = arrForSort.Length-1;

            while (i>0)
            {
                for ( j = 0; j < i; j++)
                {
                    if (arrForSort[j+1]<arrForSort[j])
                    {
                        temp = arrForSort[j+1];
                        arrForSort[j+1] = arrForSort[j];
                        arrForSort[j] = temp;
                    }
                }
                i--;//准备下一次起泡序列的长度
            }

            return arrForSort;
        }
    }
}
